<?php

namespace  Ekadmin\Controller;
use \Think\Controller;
use Think\Page;
use Vendor\Tree;

class NewsController extends CommonController
{
        public  function index()
        {
            $where['uniacid'] = $this->acid;

            $obj = M('news');
            $count = $obj->where($where)->count();
            $page = new Page($count);
            $list = $obj->where($where)->limit($page->firstRow.','.$page->listRows)->select();
            $this->assign('page',$page->show());
            $this->assign('count',$count);
            $this->assign('list',$list);
            $this->display();
        }


        public function  edit()
        {


            $data = M('news')->find(I('post.id'));



            $this->assign('data',$data);
            $this->display('form');
        }


        public function add()
        {

            $this->display('form');
        }
       



        public function update()
        {
            if(IS_POST){
                $param = I('post.');

                $obj = M('news');
                if($param['id']){
                    $obj->save($param);
                }else{

                    $param['addtime'] = time();
                    $param['uniacid'] = $this->acid;
                    $obj->add($param);
                }

                ajax_return(0,'保存成功',U('index'));




            }
        }






    public function del()
    {
        if(IS_POST){
            $param = I('id');

            if(is_array($param)){
                $map['id'] = array('in',$param);
            }else{
                $map['id'] = $param;
            }

            M('news')->where($map)->delete();

            ajax_return(0,'删除成功');
        }
    }


}